#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START readline
# depends: ncurses

reset_mtime readline readline/configure.ac
rm -rf build/readline
mkdir -p build/readline
cd build/readline
cat > config.cache << EOF
ac_cv_func_mmap_fixed_mapped=yes
ac_cv_func_strcoll_works=yes
ac_cv_func_working_mktime=yes
bash_cv_termcap_lib=libtinfo
bash_cv_func_sigsetjmp=present
bash_cv_getcwd_malloc=yes
bash_cv_job_control_missing=present
bash_cv_printf_a_format=yes
bash_cv_sys_named_pipes=present
bash_cv_ulimit_maxfds=yes
bash_cv_under_sys_siglist=yes
bash_cv_unusable_rtsigs=no
gt_cv_int_divbyzero_sigfpe=yes
EOF
../../readline/configure \
	${CONFIGURE_ARGS} \
	--cache-file=config.cache \
	${AUTOCRAP_KLUDGE}

cd ../..
make_build build/readline

mkdir -p -m 755 "$stage/${sysconfdir}"
cat > "$stage/${sysconfdir}/inputrc" <<EOF
set show-all-if-ambiguous off

# 8Bits support.
set meta-flag on
set convert-meta off
set input-meta on
set output-meta on

# common
"\e[1~": beginning-of-line
"\e[2~": quoted-insert
"\e[3~": delete-char
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[A": previous-history
"\e[B": next-history
"\e[C": forward-char
"\e[D": backward-char

# xterm
"\e[H": beginning-of-line
"\e[F": end-of-line
"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward
"\e[1;5C": forward-word
"\e[1;5D": backward-word

# rxvt
"\e[7~": beginning-of-line
"\e[8~": end-of-line
"\eOa": history-search-backward
"\eOb": history-search-forward
"\eOc": forward-word
"\eOd": backward-word

# on nxterms
"\e[\C-@": beginning-of-line
"\e[e": end-of-line

#if term=xterm
#
# Application keypad and cursor of xterm
# with NumLock ON
#
# Operators
"\eOo": "/"
"\eOj": "*"
"\eOm": "-"
"\eOk": "+"
"\eOl": "+"
"\eOM": accept-line

# Colon and dot
# "\eOl": ","
"\eOn":	"."

# Numbers
"\eOp": "0"
"\eOq": "1"
"\eOr": "2"
"\eOs": "3"
"\eOt": "4"
"\eOu": "5"
"\eOv": "6"
"\eOw": "7"
"\eOx": "8"
"\eOy": "9"
#endif xterm

#
# Application keypad and cursor of xterm
#
"\eOA": previous-history
"\eOB": next-history
"\eOC": forward-char
"\eOD": backward-char
"\eOE": re-read-init-file
"\eOF": end-of-line
"\eOH": beginning-of-line
EOF

# RECIPE END readline
